{% for i in content %}
    <tr class="gradeA odd" role="row">
        <td class="sorting_1">{{ forloop.counter }}</td>
        <td class="center">{{ i.name }}</td>
        <td class="center">{{ i.username }}</td>
        <td class="center"><a id="show{{ i.id }}" onclick="showPwd('{{ i.id }}')">******</a>
            <input type="hidden" value="{{ i.password }}" id="pwd{{ i.id }}">
        </td>
        <td class="center">{{ i.ctime }}</td>
        <td class="center">{{ i.utime }}</td>
        <td class="center">
            <a data-row="{{ i.id }}|{{ i.name }}|{{ i.username }}|{{ i.password }}|{{ i.comment }}" class="btn btn-xs btn-success btn-edit" data-toggle="modal" value="编辑" data-target="#editInfoModal">编辑</a>
            <a class="btn btn-xs btn-danger" id="system_user_delete_{{ i.id }}">删除</a>
        </td>
    </tr>

    <script>
        /**
         * 编辑表单
         * **/

        $('.btn-edit').on('click', function (event) {

            var btn = $(event.target);
            var row = btn.data('row').split('|');

            $('#user_id').val(row[0]);
            $('#name').val(row[1]);
            $('#username').val(row[2]);
            $('#password').val(row[3]);
            $('#comment').val(row[4]);
        })

        /*
        *删除信息
        */
        $("table tbody tr td a[id^='system_user_delete']").click(function () {
            var id_val = $(this).attr('id');
            var id = id_val.split('_')[3];
            var data = {"id": id};
            data = JSON.stringify(data);
            var url = "/cmdb/system_user_delete/";

            var index = layer.confirm('确定删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post(url, {data: data}, function (msg) {
                    ajax_callback(msg);
                });
            }, function () {
                layer.close(index)
            });
        });


        /*
        *保存编辑服务器信息数据
        */
        $('#editSave').click(function () {
            var Id = $("#user_id").val();
            var name = $("#name").val();
            var username = $("#username").val();
            var password = $("#password").val();
            var comment = $("#comment").val();
            data = {
                "name": name,
                "username": username,
                "password": password,
                "comment": comment,
                "id": Id
            };
            data = JSON.stringify(data);
            var url = "/cmdb/system_user_edit/";

            $.post(url, {data: data}, function (msg) {
                $('#editInfoModal').modal('hide')
                ajax_callback(msg);
            });
        });

        /*
        *ajax get callback
        */
        function ajax_callback(msg) {
            var msg = $.parseJSON(msg);
            var index = layer.alert(msg, { //layer控件提示信息
                skin: 'layui-layer-molv' //样式类名
            }, function () {
                if (msg == '成功') {
                    window.location = "/cmdb/system_user/";
                }
                else if (msg == '失败') {
                    window.location = "/cmdb/system_user/";
                }
                    {#        else if (msg == '无权限操作'){#}
                    {#            window.location="/cmdb/server_list/";#}
                    {#        }#}
                else {
                    layer.close(index)
                }
            });
        }

        $('#reset').click(function reset() {
            $('#add_GroupName').val("");
            $('#add_Comment').val("");
        });
    </script>
{% endfor %}